package com.hometeacher.api.service;

import com.hometeacher.api.model.StuList;
import com.hometeacher.api.model.User;
import com.hometeacher.api.repository.StuListRepository;
import com.hometeacher.api.repository.UsersRepository;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author ZhaoYuan
 * @data 04/04/2020 21:00
 */
@Service
@Slf4j
public class StudentService {
    @Autowired
    StuListRepository stuListRepository;

    @Autowired
    UsersRepository usersRepository;

    public List<StuList> findAllStudentInfo(){
//        log.info("!!!!!!!! {}", stuListRepository.findAll().get(0).getStuName());
        return stuListRepository.findAll();
    }
    public StuList findByUser(User user){
        Long uid = usersRepository.findUserByUsername(user.getUsername()).getUid();
        return stuListRepository.findByUid(uid);

    }

    public StuList save(StuList stuList){
        return stuListRepository.save(stuList);
    }


}
